<?php
function getValidate($type){
	try{
	include_once "smsapi/SMSAPI5.php";
	if(isset($_REQUEST['mobile'])){
		$mobile = trim($_REQUEST['mobile']);
		if (!preg_match('/^((\\+)?\\d{1,4}-)?((13|15|18)[0-9]{9})$/', $mobile))
		{
			exit("invalide");
		}
		if($type == "register" && $GLOBALS['user']->check_mobile($mobile)){
			exit("exist");
		}
		if($type == "getpassword" && !$GLOBALS['user']->check_mobile($mobile)){
			exit("noexist");
		}
		$message = new Message();
		$message->mobile = $mobile;
		$message->content= get_randnum();
		
		$sms_api->sendMessage($message);
		$_SESSION['user_reg_valide'] = $message->content;
		exit("true");
	}else{
		exit("false");
	}
	}catch (Exception $e){
		exit("error");
	}
}
function get_randnum () { 
	$randnum = "";
	$source = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789'; 
	for ($i = 0; $i < 5; $i++) { 
		$start = rand(1,strlen($source) - 1); 
		$randnum .= substr($source,$start,1); 
	}
	return $randnum;
} 
?>